package com.ezscript.print;

import java.util.HashMap;
import java.util.Map;

public class LenNum {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int len =3;
		System.out.println(getResult(len));
		System.out.println("---------------------");
		printTriangle(len);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	private static void printTriangle(int len) {
		int max = len*2-1;
		int [][] arr = new int[len][max];
		
		for(int i = 0 ;i < arr.length; i++){
			for(int j = len-i -1 ;j <len + i  ; j++){
				int tempY = i -1;
				int tempX = j-1;
				if(j == len-i-1 || j== len+i -1)
					arr[i][j] = 1;
				else if(tempY <= 0 || tempX <= 0|| arr[tempY][tempX]==0 ||tempX+2 >max-1 || arr[tempY][tempX+2]==0  ){
					arr[i][j] = 0;
				}else{
					arr[i][j] = arr[tempY][tempX] + arr[tempY][tempX+2];
				}
					
			}
		}
		int maxTemp = 0;
		for(int i = 0 ; i< arr[len-1].length; i++){
			maxTemp = arr[len-1][i]>maxTemp ? arr[len-1][i]: maxTemp;
		}
		int l = String.valueOf(maxTemp).length();
		String tempStr = "";
		Map<Integer,String> tempMap = new HashMap<Integer,String>();
		for(int i=1 ; i<= l; i++){
			tempStr +=" ";
			tempMap.put(i , tempStr);
		}
		tempMap.put(0, "");
		
		for(int i = 0; i< arr.length; i++){
			for(int j = 0 ; j< arr[i].length ; j++){
				String a = String.valueOf(arr[i][j]);
				int al = a.length();
				String res =arr[i][j] == 0? tempStr
						: a + tempMap.get(l - al);
				System.out.print(res );
			}
			System.out.println();
		}
		
		for(int i = arr.length -2; i>= 0; i--){
			for(int j = 0 ; j< arr[i].length ; j++){
				String a = String.valueOf(arr[i][j]);
				int al = a.length();
				String res =arr[i][j] == 0? tempStr
						: a + tempMap.get(l - al);
				System.out.print(res );
			}
			System.out.println();
		}
	}













	public static String getResult(int len){
		int count = 1;
		long sum = 0;
		String testStr = "";
		while(count <= len){
			long temp = 1;
			long tempSum =1;
			while(temp++ < count){
				tempSum = tempSum*10 + (long)temp;
			}
			sum += tempSum;
			testStr += tempSum +"+";
			count++;
		}
		return testStr.substring(0,testStr.length()-1) +"=" + sum;
	}

}
